// src/utils/auth.js
import http from '@/utils/request.js'

/**
 * 用户登录
 * @param {Object} data 登录数据
 * @param {string} data.username 用户名
 * @param {string} data.password 密码
 * @param {string} data.code 验证码
 * @param {string} data.uuid 验证码UUID
 * @returns {Promise} 返回Promise对象
 */
export const login = (data) => {
    return http({
        url: '/user/login',
        method: 'post',
        data,
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    })
}

/**
 * 管理员登录
 * @param {Object} data 登录数据
 * @param {string} data.username 用户名
 * @param {string} data.password 密码
 * @param {string} data.code 验证码
 * @param {string} data.uuid 验证码UUID
 * @returns {Promise} 返回Promise对象
 */
export const adminLogin = (data) => {
    return http({
        url: '/admin/login',
        method: 'post',
        data,
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    })
}

/**
 * 获取验证码(用户)
 * @param {string} uuid 验证码UUID
 * @returns {Promise} 返回Promise对象
 */
export const getCaptcha = (uuid) => {
    return http({
        url: '/user/getCode',
        method: 'get',
        params: { uuid }
    })
}

/**
 * 获取验证码(管理员)
 * @param {string} uuid 验证码UUID
 * @returns {Promise} 返回Promise对象
 */
export const getAdminCaptcha = (uuid) => {
    return http({
        url: '/admin/getCode',
        method: 'get',
        params: { uuid }
    })
}

/**
 * 用户登出
 * @returns {Promise} 返回Promise对象
 */
export const logout = () => {
    return http({
        url: '/user/logout',
        method: 'post'
    })
}

/**
 * 获取用户信息
 * @returns {Promise} 返回Promise对象
 */
export const getUserInfo = () => {
    return http({
        url: '/user/info',
        method: 'get'
    })
}